package x_selectionlistener;

import org.eclipse.ui.IWorkbenchPage;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.PlatformUI;

public final class ListenerAdder extends Thread {
	
	public ListenerAdder(){
		start();
	}
	
	public void run(){
		try{
			IWorkbenchWindow[] windows = PlatformUI.getWorkbench().getWorkbenchWindows();
			for (int i = 0; i < windows.length; i++) {
				IWorkbenchWindow window = windows[i];
				if(window != null){
					IWorkbenchPage activePage = window.getActivePage();
					while(activePage == null){
						sleep(500);
						activePage = window.getActivePage();
					}
					// add the event dispatcher as part listener
					activePage.addPartListener(ClassTabChangeEventDispatcher.getInstance());
					//System.out.println("[ListenerAdder] ClassTabChangeEventDispatcher is listening");
				}
			}
		} catch (Exception e){
			e.printStackTrace();
		}
	}

}
